<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加优惠券</title>
</head>
<script src="/jquery/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="/layui/css/layui.css">
<script src="/layui/layui.js"></script>
<link rel="stylesheet" href="/css/Coupons/addCoupon.css"/>
<body>
<div class="bodyBox">
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-card headerCenter">
                <div class="layui-card-header backColor">
                    添加优惠券
                    <div class="btnRight" style="margin-bottom: 10px">
                        <button onclick="backOff()" type="button" class="layui-btn layui-btn layui-btn-sm">
                            <i class="layui-icon layui-icon-return"></i>
                            返回
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="box">
        <form class="layui-form" action="" id="addProduct">
            <div class="layui-form-item">
                <label class="layui-form-label">优惠券名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="couponName" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">优惠券金额：</label>
                <div class="layui-input-inline">
                    <input type="text" name="couponPrice" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">发行数量：</label>
                <div class="layui-input-inline">
                    <input type="text" name="issueQuantity" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间：</label>
                <div class="layui-input-inline">
                    <input type="text" name="startDate" id="startDate" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间：</label>
                <div class="layui-input-inline">
                    <input type="text" name="endDate" id="endDate" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">上线/下线</label>
                <div class="layui-input-block">
                    <input type="radio" lay-filter="sex"  name="online" value="2" title="上线" checked>
                    <input type="radio" lay-filter="sex" name="online" value="3" title="下线">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">发送方式：</label>
                <div class="layui-input-block " style="margin-bottom: 50px">
                    <select name="grant" lay-verify="required">
                        <option value="">请选择状态</option>
                        <option value="2">自动发放</option>
                        <option value="3">活动领取</option>
                        <option value="4">人工发放</option>
                        <option value="5">无限制</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block " style="margin-bottom: 50px">
                    <button type="button" class="layui-btn" lay-submit lay-filter="formDemo">完成，添加优惠券</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['jquery','upload','form','layer','element','laydate'],function () {
        var $ = layui.$,
            element = layui.element,
            layer = layui.layer,
            upload = layui.upload,
            form = layui.form;
        laydate  = layui.laydate;

        var user = JSON.parse(localStorage.getItem('user'));

        //设置日期
        laydate.render({
            elem:'#startDate',
            type:'datetime'
        })
        laydate.render({
            elem: '#endDate'
            ,type: 'datetime'
        });

        //添加优惠券
        form.on('submit(formDemo)', function(data){
            data.field.createId = 1001;
            $.ajax({
                url:'/Coupon/addCoupon',
                type: 'post',
                dataType:'json',
                data:data.field,
                success:function (data) {
                    if(data.data){
                        layer.msg("添加成功");
                    }else{
                        layer.msg("添加失败");
                    }
                }
            });
            return false;
        });

        //返回首页
        backOff = function backOff(){
            parent.jumpSystemHome();
        }
    })
</script>
</body>
</html>